const mysql = require('mysql')
const pool = mysql.createConnection({
  host: '127.0.0.1',
  user: 'root',
  password: 'root',
  // 数据库名称
  database: 'school-c2c'
})


const exec = (sql, pramas) => {
  return new Promise((resolve, reject) => {
    pool.getConnection((err, conn) => {
      if (err) {
        console.log("数据库连接失败:" + err);
        reject(err)
      }
      conn.query(sql, pramas, (err, result) => {
        if (err) {
          console.log("SQL语句执行失败:" + err);
          reject(err);
        }
        resolve(result);
        conn.release();//释放链接 

      });
    })
  })
}

module.exports = {
  exec
}